package com.pro.control;

import com.pro.entity.Authority;
import com.pro.entity.JsonData;
import com.pro.entity.UserAuthority;
import com.pro.service.UserAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: UserAuthorityController
 * @Author: 笑笑
 * @DATE: 2021/11/11
 * @TIME: 下午 07:38
 */
@RestController
@RequestMapping("/UserAuthority")
public class UserAuthorityController {

    @Autowired
    private UserAuthorityService userAuthorityService;

    //查询所有权限信息
    @RequestMapping("/getAllAuthority")
    public JsonData getAllAuthority() {
        List<Authority> allAuthority = userAuthorityService.getAllAuthority();
        return allAuthority.size() > 0 ? JsonData.buildSuccess(allAuthority) : JsonData.buildError("服务器错误");
    }

    //根据用户id查询权限信息
    @RequestMapping("/getByUserId")
    public JsonData getByUserId(Integer id) {
        List<Authority> byUserId = null;
        try {
            byUserId = userAuthorityService.getByUserId(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return byUserId.size() > 0 ? JsonData.buildSuccess(byUserId) : JsonData.buildError("服务器错误");
    }

    //添加用户权限信息
    @RequestMapping("/addUserAuthority")
    public JsonData addUserAuthority(UserAuthority userAuthority) {
        Boolean aBoolean = userAuthorityService.addUserAuthority(userAuthority);
        return aBoolean ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("服务器错误");
    }

    //删除用户权限信息
    @RequestMapping("/DeleteUserAuthority")
    public JsonData DeleteUserAuthority(UserAuthority userAuthority) {
        Boolean aBoolean = null;
        try {
            aBoolean = userAuthorityService.DeleteUserAuthority(userAuthority);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return aBoolean ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("服务器错误");
    }
}
